package com.itheima.work1124;

import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class OutputHero {
    public static void main(String[] args) throws Exception {
        //读取文件
//        DataOutputStream dos = new DataOutputStream(new FileOutputStream("E:\\Develop\\HMziliao\\JavaSE进阶-相关资料\\课后作业\\day10\\hero.txt"));
        FileReader fr = new FileReader("E:\\Develop\\HMziliao\\JavaSE进阶-相关资料\\课后作业\\day10\\hero(1).txt", Charset.forName("GBK"));
        BufferedReader br = new BufferedReader(fr);
        ArrayList<Hero> heroes = new ArrayList<Hero>();
        String header = br.readLine();
        while ((header = br.readLine()) != null) {
            String[] heroInfo = header.split(",+");
            String Name = heroInfo[0].trim();
            int hp = Integer.parseInt(heroInfo[1].trim());
            int att = Integer.parseInt(heroInfo[2].trim());
            int pp = Integer.parseInt(heroInfo[3].trim());
            Hero hero = new Hero(Name, hp, att, pp);
            hero.lifescores = hero.lifescore();
            heroes.add(hero);
        }

        heroes.sort((h1, h2) -> Double.compare(h2.lifescores, h1.lifescores));
        heroes.forEach(System.out::println);

        FileWriter fw = new FileWriter("E:\\Develop\\HMziliao\\JavaSE进阶-相关资料\\课后作业\\day10\\hero.txt", Charset.forName("GBK"));
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write("姓名,生存,攻击,效果,新手适应分值\n");
        for (Hero hero1 : heroes) {
            bw.write(hero1.toString() + "\n");
        }
        bw.newLine();


        br.close();
        bw.close();


    }
}
